package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DzShiti;
import com.ruoyi.system.service.IDzShitiService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 试卷题目关联Controller
 * 
 * @author ruoyi
 * @date 2022-09-02
 */
@RestController
@RequestMapping("/system/shiti")
public class DzShitiController extends BaseController
{
    @Autowired
    private IDzShitiService dzShitiService;

    /**
     * 查询试卷题目关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:shiti:list')")
    @GetMapping("/list")
    public TableDataInfo list(DzShiti dzShiti)
    {
        startPage();
        List<DzShiti> list = dzShitiService.selectDzShitiList(dzShiti);
        return getDataTable(list);
    }

    /**
     * 导出试卷题目关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:shiti:export')")
    @Log(title = "试卷题目关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DzShiti dzShiti)
    {
        List<DzShiti> list = dzShitiService.selectDzShitiList(dzShiti);
        ExcelUtil<DzShiti> util = new ExcelUtil<DzShiti>(DzShiti.class);
        util.exportExcel(response, list, "试卷题目关联数据");
    }

    /**
     * 获取试卷题目关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:shiti:query')")
    @GetMapping(value = "/{stId}")
    public AjaxResult getInfo(@PathVariable("stId") Long stId)
    {
        return AjaxResult.success(dzShitiService.selectDzShitiByStId(stId));
    }

    /**
     * 新增试卷题目关联
     */
    @PreAuthorize("@ss.hasPermi('system:shiti:add')")
    @Log(title = "试卷题目关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DzShiti dzShiti)
    {
        return toAjax(dzShitiService.insertDzShiti(dzShiti));
    }

    @Log(title = "试卷题目关联", businessType = BusinessType.INSERT)
    @PostMapping("/addList")
    public AjaxResult addList(@RequestBody List<DzShiti> dzShitiList)
    {
        return toAjax(dzShitiService.insertBatchDzShiti(dzShitiList));
    }


    /**
     * 修改试卷题目关联
     */
    @PreAuthorize("@ss.hasPermi('system:shiti:edit')")
    @Log(title = "试卷题目关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DzShiti dzShiti)
    {
        return toAjax(dzShitiService.updateDzShiti(dzShiti));
    }

    /**
     * 删除试卷题目关联
     */
    @PreAuthorize("@ss.hasPermi('system:shiti:remove')")
    @Log(title = "试卷题目关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stIds}")
    public AjaxResult remove(@PathVariable Long[] stIds)
    {
        return toAjax(dzShitiService.deleteDzShitiByStIds(stIds));
    }
}
